/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.MemberDao;
import entity.Member;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.Money;

/**
 *
 * @author zhang
 */
@WebServlet("/amos")
public class AddMoneyServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        float addMoney=Float.parseFloat(req.getParameter("addmoney"));
        String name=(String)req.getSession().getAttribute("username");
        Member member=new MemberDao().getMemberByName(name);
        Boolean bool=new Money().addMoney(member.getId(),addMoney,member.getMoney());
        
        resp.setContentType("text/html;charset=utf-8");
        if(bool==false){
            resp.getWriter().println("<h1>充值失败！</h1>");
        }
        else{          
            resp.getWriter().println("<h1>账户充值成功！</h1>");
        }
        resp.getWriter().println("<a href='Member.jsp?name="+name+"'>返回个人主页</a>");
    }
    
}
